/**
 * 
 */
package app.maker.service;

import java.util.ArrayList;
import java.util.List;

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;

import app.maker.entity.Ticket;
import app.maker.entity.User;
import app.maker.error.TicketException;
import app.maker.error.UserException;
import app.maker.metier.ticketIntf.IGestionTicket;

public class TicketService {
	private Context context;

	private IGestionTicket gTicket;

	public TicketService() throws NamingException {
		super();
		context = new InitialContext();
		gTicket = (IGestionTicket) context.lookup("gestionTicket");
	}

	public Boolean creer(Ticket ticket, User source, User pilote)
			throws UserException, TicketException {
		gTicket.creerTicket(ticket, source, pilote);
		return true;
	}

	public List<Ticket> listAll() throws TicketException {
		return gTicket.getAllTicketsBD();
	}

	public List<User> listAllSource(List<Ticket> listeTickets)
			throws TicketException {
		List<User> liste = new ArrayList<User>();
		for (Ticket t : listeTickets) {
			liste.add(gTicket.getSource(t.getIdTicket()));
		}
		return liste;
	}

	public List<Ticket> listTicketsOuvert() {
		return null;
	}

	public List<Ticket> listTicketsFerme() {
		return null;
	}

}
